<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2011 Florian Müller <it-admin@ifp-potsdam.co>, IFP
*  
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 3 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
 * Stamkurs
 */
class Tx_IfpCurriculum2_Domain_Model_Kursstamm extends Tx_Extbase_DomainObject_AbstractEntity {

	/**
	 * Kursnummer
	 *
	 * @var integer
	 * @validate NotEmpty
	 */
	protected $kursNr;
/**
	 * Titel des Kurse
	 *
	 * @var string
	 */
	protected $titel;
	/**
	 * turnus
	 *
	 * @var string
	 */
	protected $turnus;

	/**
	 * Unterrichtseinheiten
	 *
	 * @var integer
	 */
	protected $ue;

	/**
	 * Kurse
	 *
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Kurs>
	 */
	protected $kurse;

	/**
	 * Gegenstandskatalog
	 *
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog>
	 */
	protected $gegenstandskatalog;

	/**
	 * Gegenstandskatalog
	 *
	 * @var Tx_IfpCurriculum2_Domain_Model_Modul
	 */
	protected $modul;


	public function __construct() {
		//Do not remove the next line: It would break the functionality
		$this->initStorageObjects();
	}

	/**
	 * Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
	 *
	 * @return void
	 */
	protected function initStorageObjects() {
		/**
		* Do not modify this method!
		* It will be rewritten on each save in the kickstarter
		* You may modify the constructor of this class instead
		*/
		$this->kurse = new Tx_Extbase_Persistence_ObjectStorage();
		
		$this->gegenstandskatalog = new Tx_Extbase_Persistence_ObjectStorage();
	}

	/**
	 * @param integer $kursNr
	 * @return void
	 */
	public function setKursNr($kursNr) {
		$this->kursNr = $kursNr;
	}

	/**
	 * @return integer
	 */
	public function getKursNr() {
		return $this->kursNr;
	}
/**
	 * @param string $titel
	 * @return void
	 */
	public function setTitel($titel) {
		$this->titel = $titel;
	}

	/**
	 * @return string
	 */
	public function getTitel() {
		return $this->titel;
	}
	public function getTitelDetail(){
		return $this->getKursNr().": ".$this->titel;
	}

	/**
	 * @param integer $turnus
	 * @return void
	 */
	public function setTurnus($turnus) {
		$this->turnus = $turnus;
	}

	/**
	 * @return integer
	 */
	public function getTurnus() {
		return $this->turnus;
	}

	/**
	 * @param integer $ue
	 * @return void
	 */
	public function setUe($ue) {
		$this->ue = $ue;
	}

	/**
	 * @return integer
	 */
	public function getUe() {
		return $this->ue;
	}

	/**
	 * @param Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Kurs> $kurse
	 * @return void
	 */
	public function setKurse(Tx_Extbase_Persistence_ObjectStorage $kurse) {
		$this->kurse = $kurse;
	}

	/**
	 * @return Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Kurs>
	 */
	public function getKurse() {
		return $this->kurse;
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Kurs the Kurs to be added
	 * @return void
	 */
	public function addKurse(Tx_IfpCurriculum2_Domain_Model_Kurs $kurse) {
		$this->kurse->attach($kurse);
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Kurs the Kurs to be removed
	 * @return void
	 */
	public function removeKurse(Tx_IfpCurriculum2_Domain_Model_Kurs $kurseToRemove) {
		$this->kurse->detach($kurseToRemove);
	}

	/**
	 * @param Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog> $gegenstandskatalog
	 * @return void
	 */
	public function setGegenstandskatalog(Tx_Extbase_Persistence_ObjectStorage $gegenstandskatalog) {
		$this->gegenstandskatalog = $gegenstandskatalog;
	}

	/**
	 * @return Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog>
	 */
	public function getGegenstandskatalog() {
		return $this->gegenstandskatalog;
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog the Gegenstandskatalog to be added
	 * @return void
	 */
	public function addGegenstandskatalog(Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog $gegenstandskatalog) {
		$this->gegenstandskatalog->attach($gegenstandskatalog);
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog the Gegenstandskatalog to be removed
	 * @return void
	 */
	public function removeGegenstandskatalog(Tx_IfpCurriculum2_Domain_Model_Gegenstandskatalog $gegenstandskatalogToRemove) {
		$this->gegenstandskatalog->detach($gegenstandskatalogToRemove);
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Modul $modul
	 * @return void
	 */
	public function setModul(Tx_IfpCurriculum2_Domain_Model_Modul $modul) {
		$this->modul = $modul;
	}

	/**
	 * @return Tx_IfpCurriculum2_Domain_Model_Modul
	 */
	public function getModul() {
		return $this->modul;
	}
	/**
	 * 
	 * Enter description here ...
	 * @return string
	 */
	public function getModulname(){
		//var_dump($this->modul);
		return $this->modul->getCode()."-".$this->getTurnus();
	}
	
	public function getNextVersion(){
		$version=0;
		$kurse=$this->getKurse()->toArray();
		foreach ($kurse as $kurs) {
			if($version<$kurs->getVersion())
				$version=$kurs->getVersion();
		}
		$version++;
		return $version;
	}

}
?>